package com.xsmart.payment.services;

import com.baomidou.mybatisplus.plugins.Page;
import com.xsmart.common.constant.ResultConstant;
import com.xsmart.common.entity.RequestBean;
import com.xsmart.common.entity.ResponseBean;
import com.xsmart.payment.dao.PaymentConfigruationDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class PaymentConfigruationService {
    @Autowired
    PaymentConfigruationDao paymentConfigruationDao;

    /**
     * 查询支付配置
     * @param requestBean
     * @return
     */
    public ResponseBean queryPaymentConfigruation(RequestBean requestBean){
        int currentPage = requestBean.
                getRequestParamInteger("currentPage",
                        1);
        int pageSize = requestBean.
                getRequestParamInteger("pageSize",
                        10);
        String pay_code = requestBean.getRequestParamString("pay_code");
        Integer enabled = requestBean.getRequestParamInteger("enabled");
        Map<String, Object> paymentConfigruationMap = new HashMap<>();
        paymentConfigruationMap.put("pay_code", pay_code);
        paymentConfigruationMap.put("enabled", enabled);
        ResponseBean responseBean = requestBean.getResponseBean();
        Page<Map<String, Object>> page = new Page<>(currentPage, pageSize);
        page.setRecords(paymentConfigruationDao.queryPaymentConfigruation(page,paymentConfigruationMap));
        responseBean.addResultPageItem("paymentConfigruationList", page);
        responseBean.setResult(ResultConstant.SUCCESS);

        return responseBean;
    }

    /**
     * 查询所有支付配置
     * @param requestBean
     * @return
     */
    public ResponseBean queryAllPaymentConfigruation(RequestBean requestBean){
        ResponseBean responseBean = requestBean.getResponseBean();
        List<Map<String, Object>> paymentConfigruationList = paymentConfigruationDao.queryAllPaymentConfigruation();
        responseBean.addResultItem("paymentConfigruationList", paymentConfigruationList);
        responseBean.setResult(ResultConstant.SUCCESS);
        return responseBean;
    }

    /**
     * 新增支付配置
     * @param requestBean
     * @return
     */
    public ResponseBean addPaymentConfigruation(RequestBean requestBean){
        ResponseBean responseBean = requestBean.getResponseBean();
        String pay_code = requestBean.getRequestParamString("pay_code");
        String pay_name = requestBean.getRequestParamString("pay_name");
        String pay_fee = requestBean.getRequestParamString("pay_fee");
        String pay_desc = requestBean.getRequestParamString("pay_desc");
        Integer pay_order = requestBean.getRequestParamInteger("pay_order");
        String pay_config = requestBean.getRequestParamString("pay_config");
        Integer enabled = requestBean.getRequestParamInteger("enabled");
        Integer is_cod = requestBean.getRequestParamInteger("is_cod");
        Integer is_online = requestBean.getRequestParamInteger("is_online");
        Map<String, Object> map = new HashMap<>();
        map.put("pay_code", pay_code);
        map.put("pay_name", pay_name);
        map.put("pay_fee", pay_fee);
        map.put("pay_desc", pay_desc);
        map.put("pay_order", pay_order);
        map.put("pay_config", pay_config);
        map.put("enabled", enabled);
        map.put("is_cod", is_cod);
        map.put("is_online", is_online);
        int num = paymentConfigruationDao.addPaymentConfigruation(map);
        responseBean.setResult(ResultConstant.SUCCESS);

        return responseBean;
    }

    /**
     * 修改支付配置
     * @param requestBean
     * @return
     */
    public ResponseBean modPaymentConfigruation(RequestBean requestBean){
        ResponseBean responseBean = requestBean.getResponseBean();
        Integer pay_id = requestBean.getRequestParamInteger("pay_id");
        String pay_code = requestBean.getRequestParamString("pay_code");
        String pay_name = requestBean.getRequestParamString("pay_name");
        String pay_fee = requestBean.getRequestParamString("pay_fee");
        String pay_desc = requestBean.getRequestParamString("pay_desc");
        Integer pay_order = requestBean.getRequestParamInteger("pay_order");
        String pay_config = requestBean.getRequestParamString("pay_config");
        Integer enabled = requestBean.getRequestParamInteger("enabled");
        Integer is_cod = requestBean.getRequestParamInteger("is_cod");
        Integer is_online = requestBean.getRequestParamInteger("is_online");
        Map<String, Object> map = new HashMap<>();
        map.put("pay_id", pay_id);
        map.put("pay_code", pay_code);
        map.put("pay_name", pay_name);
        map.put("pay_fee", pay_fee);
        map.put("pay_desc", pay_desc);
        map.put("pay_order", pay_order);
        map.put("pay_config", pay_config);
        map.put("enabled", enabled);
        map.put("is_cod", is_cod);
        map.put("is_online", is_online);
        int num = paymentConfigruationDao.modPaymentConfigruation(map);
        responseBean.setResult(ResultConstant.SUCCESS);
        return responseBean;
    }

    /**
     * 删除
     * @param requestBean
     * @return
     */
    public ResponseBean delPaymentConfigruation(RequestBean requestBean){
        ResponseBean responseBean = requestBean.getResponseBean();
        Integer pay_id = requestBean.getRequestParamInteger("pay_id");
        int num = paymentConfigruationDao.delPaymentConfigruation(pay_id);
        return responseBean;
    }
}
